package org.hncors.gnssparse.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.hncors.gnssparse.R;
import org.hncors.gnssparse.model.LocationItemData;
import org.hncors.gnssparse.model.SatelliteItemData;

import java.util.ArrayList;

/**
 * Created by Yagui Cheng(240654418@qq.com) on 2018/8/6.
 */

public class LocationItemAdapter extends BaseAdapter {
        private Context mContext;
        private LayoutInflater mLayoutInflater;
    private ArrayList<LocationItemData> mSateItemsDataArray;
        public LocationItemAdapter(Context context, ArrayList<LocationItemData> mList) {
            mContext = context;
            mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mSateItemsDataArray = mList;
        }

        @Override
        public int getCount() {
            return mSateItemsDataArray.size();
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null)
                convertView = mLayoutInflater.inflate(R.layout.layout_gnss_history_satellite_list_item, null);

            LocationItemData item = mSateItemsDataArray.get(position);
            TextView numTv = (TextView) convertView.findViewById(R.id.num_tv);
            if (numTv != null)
                numTv.setText((position + 1) + "");

            //SNRL
            TextView locationTv = (TextView) convertView.findViewById(R.id.location_tv);
            if (locationTv != null)
                locationTv.setText(item.bValue + "\n"
                + item.lValue + "\n" + item.hValue);


            TextView timeTv = (TextView) convertView.findViewById(R.id.time_tv);
            if (timeTv != null)
                timeTv.setText(item.timeStr);

            TextView statusTv = (TextView) convertView.findViewById(R.id.status_tv);
            if (statusTv != null)
                statusTv.setText(item.mSatelliteStatus);

            return convertView;
        }
}
